{include file="public/head"}
    <body>
    <div class="x-body">
      <div  class="lotus-nav" >
            <button class="layui-btn  layui-btn-sm"
            onclick="x_admin_show('添加用户','addUser.html',500,410)">
               <i class="layui-icon layui-icon-add-circle"></i>
            </button>

          <div class="layui-input-inline">
              <input value="{php}echo isset($_GET['username'])?$_GET['username']:'';{/php}"  name="username"   class="layui-input lotus-input"  placeholder="请输入登录名搜索">
          </div>

            <button class="layui-btn layui-btn-sm search-query"><i class="layui-icon layui-icon-search"></i></button>
            
            <span class="x-right">共有数据:<i class="i_count" style="color: red;font-size: 22px">{$users->total()}</i>条 <button onclick="javascript:location.reload()" class="layui-btn layui-btn-xs"><i class="icon iconfont ">&#xe6aa;</i></button></span>

       </div>

    <table class="layui-table">
        <thead>
          <tr>
            <th>值班人员</th>
            <th>注册邮箱</th>
            <th>手机号</th>
            <th>所属科室</th>
            <th>历史工单数</th>
            <th>最后登录时间</th>
            <th>操作</th>
        </thead>
        <tbody>

        {volist name="users" id="vo"}
        	<tr>
	            <td>{$vo.username}</td>
              <td>{$vo.email}</td>
              <td>{$vo.mobile}</td>
              <td>
                {eq name='$vo["dutyRoom"]' value="1"}
                <span>科室一</span>
                {/eq}
                {eq name='$vo["dutyRoom"]' value="2"}
                <span>科室二</span>
                {/eq}
                {eq name='$vo["dutyRoom"]' value="3"}
                <span>科室三</span>
                {/eq}
                {eq name='$vo["dutyRoom"]' value="4"}
                <span>科室四</span>
                {/eq}
                {eq name='$vo["dutyRoom"]' value="5"}
                <span>科室五</span>
                {/eq}
              </td>
              <td>{$vo.achPro}</td>
	            <td>
                {if condition="empty($vo.last_login_time)"}
                     此用户还未使用
                {else /}
                    {$vo.last_login_time}
                {/if}
              </td>
        

	            <td>
	<button class="layui-btn layui-btn-xs" onclick="x_admin_show('编辑用户','editUser.html?id={$vo.id}',500,410)">编辑</button>
	             	<button onclick="delUser(this,{$vo.id})" class="layui-btn layui-btn-xs layui-btn-danger">删除</button>
	           </td>
	        </tr>
        {/volist}
       
        </tbody>
      </table>
	      <div class="page">
	        <div>
	        	{$users->render()}
	        </div>
	      </div>
    </div>
</body>
{include file="public/foot"}
    <script>
        var layer = layui.layer
            ,form = layui.form;


        $(".search-query").click(function () {
            var username = $("input[name=username]").val();
            window.location.href = 'userlist.html?username='+username;
        });

       /*用户-停用*/
      function member_stop(obj,id){
          layer.confirm('确认要停用吗？',function(index){
              if($(obj).attr('title')=='启用'){
                //发异步把用户状态进行更改
                $(obj).attr('title','停用')
                $(obj).find('i').html('&#xe62f;');

                $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                layer.msg('已停用!',{icon: 5,time:1000});

              }else{
                $(obj).attr('title','启用')
                $(obj).find('i').html('&#xe601;');

                $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                layer.msg('已启用!',{icon: 5,time:1000});
              }
              
          });
      }


      function delAll (argument) {
        var data = tableCheck.getData();
        layer.confirm('确认要全部删除吗？',function(index){
            //捉到所有被选中的，发异步进行删除
            layer.msg('删除成功', {icon: 1});
            $(".layui-form-checked").not('.header').parents('tr').remove();
        });
      }

      function delUser(obj,id){
        var count = $(".i_count")[0].innerText;
        layer.confirm('确认要删除吗？',function(index){
            //捉到所有被选中的，发异步进行删除
            $.post("{:url('admin/user/deleteUser')}", {id: id}, function(data, textStatus, xhr) {
          /*optional stuff to do after success */
              console.log(data);
              if(data.code==1){
                  layer.msg(data.msg,{icon:1,time:1000},function(){
                    $(obj).parents('tr').remove();
                    $(".i_count").html(count-1);
                  });
              }else{
                  layer.msg(data.msg,{icon:2,time:1000});
              }
            
            });
        });
      }
    </script>
